package com.jf.apply_car.controller;

import com.jf.apply_car.bean.Car;
import com.jf.apply_car.service.CarService;
import com.jf.apply_car.util.ResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/car")
public class CarController {
    @Autowired
    private CarService carService;

    @GetMapping("/list")
    public String list() {
        return "car/car-list";
    }

    @GetMapping("/edit")
    public String edit() {
        return "car/car-edit";
    }

    @GetMapping("/page")
    @ResponseBody
    public ResultJson page(int page, int limit, Car car) {
        return carService.getPage(page, limit, car);
    }

    @PostMapping("/delete")
    @ResponseBody
    public ResultJson delete(int[] ids) {
        carService.delete(ids);
        return ResultJson.success();
    }

    @GetMapping("/info/{carId}")
    @ResponseBody
    public ResultJson info(@PathVariable int carId) {
        return carService.getById(carId);
    }

    @PostMapping("/update")
    @ResponseBody
    public ResultJson update(Car car) {
        carService.saveOrUpdate(car);
        return ResultJson.success();
    }

    @GetMapping("/select")
    @ResponseBody
    public ResultJson select() {
        return carService.select();
    }
}
